unit UnitySiparis;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, Wwdotdot, Wwdbcomb, StdCtrls, Mask, wwdbedit, Grids,
  Wwdbigrd, Wwdbgrid, ExtCtrls, Buttons, Menus;

type
  TUnitySiparisF = class(TForm)
    Panel1: TPanel;
    GroupBox3: TGroupBox;
    wwDBEdit6: TwwDBEdit;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Fisnok: TwwDBEdit;
    wwDBComboBox1: TwwDBComboBox;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    wwDBEdit3: TwwDBEdit;
    wwDBEdit4: TwwDBEdit;
    wwDBEdit5: TwwDBEdit;
    Panel2: TPanel;
    bkapat: TBitBtn;
    Grid1: TwwDBGrid;
    durumk: TwwDBComboBox;
    Siparis: TADOQuery;
    SiparisS: TDataSource;
    SiparisHar: TADOQuery;
    SiparisHarS: TDataSource;
    wwDBComboBox2: TwwDBComboBox;
    Label7: TLabel;
    wwDBEdit2: TwwDBEdit;
    wwDBEdit1: TwwDBEdit;
    wwDBEdit7: TwwDBEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Grid1CalcCellColors(Sender: TObject; Field: TField;
      State: TGridDrawState; Highlight: Boolean; AFont: TFont;
      ABrush: TBrush);
    procedure bkapatClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure SiparisHarAfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
  public
    SiparisID: Integer;
    { Public declarations }
  end;

var
  UnitySiparisF: TUnitySiparisF;

implementation
{$R *.dfm}

uses data, GenelListe, ana1, GeciciUretim;

procedure TUnitySiparisF.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cafree;
  UnitySiparisF := nil;
end;

procedure TUnitySiparisF.FormShow(Sender: TObject);
begin
  YerAyarla(Self, False);

  Siparis.Close;
  Siparis.SQL.text := 'select carikodu=(select carikodu from cari where cari.carikod=unity_siparis_2006.carikod),firmaadi=(select firmaadi from cari where cari.carikod=unity_siparis_2006.carikod),';
  Siparis.SQL.add('temsilcisi=(select adi from cayetkili c where c.kodu=(select temsilcisi from cari where cari.carikod=unity_siparis_2006.carikod)),depoadi=(select depoadi from depolar where depolar.id=unity_siparis_2006.depoid),* from unity_siparis_2006 where id=' + inttostr(SiparisID));
  Siparis.Open;

  Siparishar.Close;
  Siparishar.SQL.text := 'select stokkodu=(select stokkodu from stok where stok.stokkod=unity_siparishar_2006.stokkod),';
  Siparishar.SQL.add('cinsi=(select stokkodu from stok where stok.stokkod=unity_siparishar_2006.stokkod),');
  Siparishar.SQL.add('ozkod1=(select ozkod1 from stok where stok.stokkod=unity_siparishar_2006.stokkod),* from unity_siparishar_2006 ');
  Siparishar.SQL.add('where siparisid=' + inttostr(SiparisID));
  Siparishar.Open;

end;

procedure TUnitySiparisF.Grid1CalcCellColors(Sender: TObject;
  Field: TField; State: TGridDrawState; Highlight: Boolean; AFont: TFont;
  ABrush: TBrush);
begin
  afont.Color := clblack;

  if field.DataSet.FieldByName('durum').asstring = '1' then
    abrush.color := $00A6C8F0
  else
  begin
    abrush.color := clwhite;
  end;

  if Highlight = true then
  begin
    abrush.color := clnavy;
    afont.Color := clwhite;
  end;

end;

procedure TUnitySiparisF.bkapatClick(Sender: TObject);
begin
  Close;
end;

procedure TUnitySiparisF.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then
    close;
end;

procedure TUnitySiparisF.SiparisHarAfterOpen(DataSet: TDataSet);
var
  Toplam: Currency;
begin
  Toplam := 0;
  Dataset.DisableControls;
  try
    DataSet.First;
    while not DataSet.Eof do
    begin
      Toplam := Toplam + DataSet.FieldByName('ToplamFiyat').AsCurrency;
      DataSet.Next;
    end;
  finally
    DataSet.EnableControls;
    Grid1.ColumnByName('ToplamFiyat').FooterValue := CurrToStr(Toplam);
  end;
end;

end.

